package com.baitai.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baitai.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baitai.common.annotation.Log;
import com.baitai.common.core.controller.BaseController;
import com.baitai.common.core.domain.AjaxResult;
import com.baitai.common.enums.BusinessType;
import com.baitai.system.domain.UserPointsLog;
import com.baitai.system.service.IUserPointsLogService;
import com.baitai.common.utils.poi.ExcelUtil;
import com.baitai.common.core.page.TableDataInfo;

/**
 * 积分明细Controller
 * 
 * @author xx
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/system/userPointsLog")
public class UserPointsLogController extends BaseController
{
    @Autowired
    private IUserPointsLogService userPointsLogService;

    /**
     * 查询积分明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:userPointsLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserPointsLog userPointsLog)
    {
        startPage();
        List<UserPointsLog> list = userPointsLogService.selectUserPointsLogList(userPointsLog);
        return getDataTable(list);
    }

    /**
     * 导出积分明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:userPointsLog:export')")
    @Log(title = "积分明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserPointsLog userPointsLog)
    {
        List<UserPointsLog> list = userPointsLogService.selectUserPointsLogList(userPointsLog);
        ExcelUtil<UserPointsLog> util = new ExcelUtil<UserPointsLog>(UserPointsLog.class);
        util.exportExcel(response, list, "积分明细数据");
    }

    /**
     * 获取积分明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:userPointsLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userPointsLogService.selectUserPointsLogById(id));
    }

    /**
     * 新增积分明细
     */
    @PreAuthorize("@ss.hasPermi('system:userPointsLog:add')")
    @Log(title = "积分明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPointsLog userPointsLog)
    {
        return toAjax(userPointsLogService.insertUserPointsLog(userPointsLog));
    }

    /**
     * 修改积分明细
     */
    @PreAuthorize("@ss.hasPermi('system:userPointsLog:edit')")
    @Log(title = "积分明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPointsLog userPointsLog)
    {
        return toAjax(userPointsLogService.updateUserPointsLog(userPointsLog));
    }

    /**
     * 删除积分明细
     */
    @PreAuthorize("@ss.hasPermi('system:userPointsLog:remove')")
    @Log(title = "积分明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userPointsLogService.deleteUserPointsLogByIds(ids));
    }

    /**
     * 查询积分明细列表
     */
    @PostMapping("/appList")
    public AjaxResult appList(@RequestBody UserPointsLog userPointsLog)
    {
        startPage();
        userPointsLog.setUserId(SecurityUtils.getUserId());
        List<UserPointsLog> list = userPointsLogService.selectUserPointsLogList(userPointsLog);
        return AjaxResult.success(getDataTable(list));
    }

    /**
     * 新增积分明细
     */
    @Log(title = "获取积分", businessType = BusinessType.INSERT)
    @PostMapping("/gainPoints")
    public AjaxResult gainPoints(@RequestBody UserPointsLog userPointsLog)
    {
        userPointsLogService.gainPoints(SecurityUtils.getUserId(),userPointsLog.getPointsChange(),userPointsLog.getActionType(),userPointsLog.getActionDetail());
        return AjaxResult.success();
    }
}
